package com.naizhuai.ui.components;

import android.app.Activity;
import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v4.view.MotionEventCompat;
import android.support.v4.view.ViewConfigurationCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.widget.Scroller;

import com.naizhuai.util.DeviceUtils;
import com.naizhuai.util.NaizhuAILog;

/**
 * Created by code_han on 2018/4/2.
 */

public class BetterRecyclerView extends RecyclerView {
    private Scroller mScroller;
    private Activity activity;
    private LinearLayoutManager linearManager;

    public BetterRecyclerView(Context context) {
        this(context, null);
    }

    public BetterRecyclerView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BetterRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        activity = (Activity) context;
        mScroller = new Scroller(context);
    }

//    @Override
//    public void computeScroll() { //重写computeScroll()方法，并在其内部完成平滑滚动的逻辑
//        if (mScroller.computeScrollOffset()) {
//            scrollBy(mScroller.getCurrX(), mScroller.getCurrY());
//            invalidate();
//        }
//    }

//    public void scrollToPositionByScroller(int position) {
//        if (linearManager == null)
//            linearManager = (LinearLayoutManager) getLayoutManager();
//        int startPosition=linearManager.findFirstVisibleItemPosition();
//        NaizhuAILog.e("startPosition=" + startPosition);
//        NaizhuAILog.e("position=" + position);
////        int startX1 = mScroller.getCurrX();
////        int startX2 = mScroller.getStartX();
////        int startX3 = mScroller.getFinalX();
//        int start=startPosition*DeviceUtils.getScreenDevice(activity)[0];
//        int move=(position-startPosition)*DeviceUtils.getScreenDevice(activity)[0];
////        NaizhuAILog.e("startX1=" + startX1 + ";startX2=" + startX2 + ";x=" + x + ";startX3=" + startX3);
//        NaizhuAILog.e("start=" + start);
//        NaizhuAILog.e("move=" + move);
//        mScroller.startScroll(start, 0, move, 0,3000);
//        invalidate();
//    }
}
